<template>
	<view class="container">
		<navbar :background="background" :bgSize='bgSize' color="#fff" title="推广中心"></navbar>
		<view class="bg">
			<image :src="hostUrl+'/static/images/center-bg2.png'"></image>
		</view>
		<view class="wrap" v-if='showPage'>
			<view class="user-wrap">
				<view class="user-img">
					<image src='/static/user/user-default.png' v-if='!promotionInfo.avatar'></image>
					<image :src='promotionInfo.avatar' v-else></image>
				</view>
				<view class="user-nick">
					<view class="nick ellipsis">{{promotionInfo.nickname}}</view>
					<view class="call">{{promotionInfo.mobile}}</view>
				</view>
				<view class="renzheng line-center">
					<image src='../static/renzheng.png'></image>
					已认证
				</view>
			</view>
			<view class="commison-wrap">
				<!-- <view class="coin">
					<image src='../static/coin.png'></image>
				</view> -->
				<view class="top">
					<view class="top-left">
						<view class="title">可提现(元）</view>
						<view class="num">{{promotionInfo.commssion}}</view>
					</view>
					<view class="btn line-center" @tap='toPage(0)'>申请提现</view>
				</view>
				<view class="bottom">
					<view class="bottom-item">
						<view class="text">累计奖励(元)</view>
						<view class="num">{{promotionInfo.total_com}}</view>
					</view>
					<view class="bottom-item">
						<view class="text">已提现(元)</view>
						<view class="num">{{promotionInfo.total_cash}}</view>
					</view>
				</view>
			</view>
			<view class="list-wrap">
				<view class="list-item" v-for='(item,index) in list' :key="index" @tap='toPage(1,index)'>
					<view class="icon">
						<image :src='item.icon'></image>
					</view>
					<view class="text">{{item.name}}</view>
					<uni-icons type='right'></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				background: `url(${app.globalData.hostUrl}/static/images/center-bg2.png)`,
				bgSize: '100% 492rpx',
				hostUrl: app.globalData.hostUrl,
				promotionInfo: {},
				showPage:false,
				list: [{
						icon: require('../static/icon1.png'),
						name: '佣金明细',
						path: "/pages/promotion-page/record/record?type=1"
					},
					{
						icon: require('../static/icon2.png'),
						name: '提现记录',
						path: "/pages/promotion-page/record/record?type=2"
					},
					{
						icon: require('../static/icon3.png'),
						name: '推广名片',
						path: "/pages/promotion-page/invite/invite"
					},
					{
						icon: require('../static/icon4.png'),
						name: '推广统计',
						path: "/pages/promotion-page/statistics/statistics"
					},
					{
						icon: require('../static/icon5.png'),
						name: '账户信息',
						path: "/pages/promotion-page/account-info/account-info"
					},
				]
			};
		},
		onLoad() {
			uni.showLoading({
				title:'加载中...',
				mask:true
			})
			// this.getShareData()
		},
		onShow() {
			this.getShareData()
		},
		onPullDownRefresh() {
			uni.showLoading({
				title:'加载中...',
				mask:true
			})
			this.getShareData();
			uni.stopPullDownRefresh()
		},
		methods: {
			//获取分销中心数据
			getShareData() {
				let that = this;
				app.globalRequest({
					api: app.getApi().promotion.shareCenter,
				}).then(res => {
					that.showPage = true;
					if (res.code == 0) {
						that.promotionInfo = res.data;
					}
				}).catch(err => {

				})
			},
			toPage(type, index) {
				let path;
				let list = this.list;
				console.log('list', list)
				switch (Number(type)) {
					case 0:
						if (this.promotionInfo.user_account) {
							path =
								`/pages/promotion-page/withdraw-cash/withdraw-cash?money=${this.promotionInfo.commssion}`;
						}else{
							uni.showToast({
								title:'去完善账户信息',
								icon:'none'
							})
							setTimeout(()=>{
								path = '/pages/promotion-page/account-info/account-info';
								uni.navigateTo({
									url: path,
								})
							},300)
							
						}
						break;
					case 1:
						path = list[index].path;
						break;
				}
				console.log('path', path)
				uni.navigateTo({
					url: path,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg {
		width: 100%;
		height: 492rpx;
		position: absolute;
		left: 0;
		top: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.wrap {
		position: relative;
		z-index: 2;
	}

	.user-wrap {
		margin: 34rpx 36rpx 0;
		display: flex;
		align-items: center;

		.user-img {
			width: 124rpx;
			height: 124rpx;
			border: 2rpx solid #fff;
			box-sizing: border-box;
			border-radius: 100%;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.user-nick {
			flex: 1;
			overflow: hidden;
			margin: 0 24rpx;

			.nick {
				width: 100%;
				font-weight: bold;
				font-size: 32rpx;
				color: #FFFFFF;
			}

			.call {
				font-size: 24rpx;
				color: #FFFFFF;
				padding-top: 4rpx;
			}
		}

		.renzheng {
			width: 160rpx;
			height: 48rpx;
			background: linear-gradient( 181deg, #F8E5D2 0%, #FED3AA 29%, #F9C494 100%);
			box-shadow: inset 0rpx -6rpx 12rpx 2rpx #FFF0E2;
			border-radius: 24rpx;
			border: 2rpx solid #F9CA9E;
			box-sizing: border-box;
			color: #FA8E2B;
			font-size: 24rpx;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 6rpx;
			}
		}
	}

	.commison-wrap {
		width: 702rpx;
		height: 282rpx;
		background: linear-gradient( 134deg, #F6F5FA 0%, #F6F5FA 100%);
		border-radius: 24rpx;
		margin: 30rpx auto 0;
		position: relative;
		box-sizing: border-box;

		.coin {
			width: 81rpx;
			height: 101rpx;
			position: absolute;
			left: 20rpx;
			top: 24rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.top {
			margin: 0 26rpx;
			padding: 30rpx 16rpx 18rpx 30rpx;
			border-bottom: 2rpx dotted #E1ECFC;
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			z-index: 2;

			.title {
				font-size: 24rpx;
			}

			.num {
				font-family: 'DIN-BOLD';
				font-weight: bold;
				font-size: 48rpx;
				line-height: 52rpx;
				margin-top: 20rpx
			}

			.btn {
				width: 176rpx;
				height: 64rpx;
				background: linear-gradient( 124deg, #039BFE 0%, #156FF4 100%);
				box-shadow: inset 0rpx -2rpx 12rpx 2rpx #D6EDFF;
				border-radius: 40rpx;
				color: #7D3C04;
				font-size: 32rpx;
				color:#fff;
			}
		}

		.bottom {
			padding: 30rpx 50rpx 0;
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			row-gap: 20rpx;

			.bottom-item {
				.text {
					font-size: 24rpx;
				}

				.num {
					font-family: 'DIN-BOLD';
					font-weight: bold;
					font-size: 36rpx;
					line-height: 48rpx;
					padding-top: 12rpx;
				}
			}
		}
	}

	.list-wrap {
		margin: 32rpx 24rpx 0;
		background: #FFFFFF;
		border-radius: 16rpx;

		.list-item {
			margin: 0 20rpx;
			height: 96rpx;
			display: flex;
			align-items: center;

			.icon {
				width: 48rpx;
				height: 48rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.text {
				flex: 1;
				margin: 0 14rpx;
			}
		}
	}
</style>